package com.hanbitexam.dao;

import java.io.Reader;
import java.sql.SQLException;
import java.util.List;

import com.hanbitexam.vo.QuestionVo;
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

public class QuestionDao {
	private static SqlMapClient sqlmapper;
	List<QuestionVo> list;
	static{
		try{
			Reader reader = Resources.getResourceAsReader("com/hanbitexam/sqlMap/sqlMapConfig.xml");
			sqlmapper = SqlMapClientBuilder.buildSqlMapClient(reader);
			reader.close();
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public static List selectAllQuestion() throws Exception{
		return sqlmapper.queryForList("selectAllQuestion");
	}
	
	public static QuestionVo selectQuestion(int idx) throws Exception{
		return (QuestionVo)sqlmapper.queryForObject("selectQuestion",idx);
	}
	
	public static void deleteQuestion(int idx) throws Exception{
		sqlmapper.delete("deleteQuestion",idx);
	}
	
	public static void updateQuestion(QuestionVo vo) throws Exception{
		sqlmapper.update("updateQuestion",vo);
	}
	
	public static void startTransaction() throws SQLException {
		sqlmapper.startTransaction();
	}
	
	public static void endTransaction() throws SQLException {
		sqlmapper.endTransaction();
	}
	
	public static void insertQuestion(QuestionVo vo) throws Exception{
		System.out.println("+++QuestionDao's InsertQuestion");
		sqlmapper.insert("insertQuestion", vo);
		
	}
	
	public static List selectQuestionByCategory(int idx ) throws Exception{
		return sqlmapper.queryForList("selectQuestionByCategory",idx);
	}
	
	public static void updateLast(int idx) throws Exception{
		System.out.println("+++QuestionDao's updateLast");
		sqlmapper.update("updateLast", idx);
		
	}
	
}
